package com.example.controller;

import com.example.common.Result;
import com.example.entity.Apply;
import com.example.service.ApplyService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/apply")
public class ApplyController {

    @Autowired
    private ApplyService applyService;

    @GetMapping("/selectAll")
    public Result selectAll(Apply apply){
        List<Apply> applyslist=applyService.selectAll(apply);
        return Result.success(applyslist);
    }

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             Apply apply){
        PageInfo<Apply> applyPageInfo = applyService.selectPage(pageNum, pageSize,apply);
        return Result.success(applyPageInfo);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Apply apply){
        applyService.add(apply);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Apply apply){
        applyService.update(apply);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        applyService.deleteById(id);
        return Result.success();
    }

}
